<%--
 * @fileName save.jsp
 * @author  科泰集团教研团队
 * @createTime 2024/10/13 21:57
 * @lastModify 2024/10/13 21:57
 * @version 1.0.0
 --%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title>科泰超市管理系统</title>
    <%--  导入公共头部信息  --%>
    <%@include file="/WEB-INF/layout/head.jsp" %>
    <%--  有其他css样式可以在这里引入或编写  --%>
</head>

<body class="nav-md">
<div class="container body">
    <div class="main_container">
        <!-- 引入左边导航菜单 -->
        <jsp:include page="/WEB-INF/layout/left-nav.jsp"></jsp:include>
        <!-- 引入左边导航菜单 -->

        <!-- 引入顶部导航 -->
        <jsp:include page="/WEB-INF/layout/top-nav.jsp"></jsp:include>
        <!-- 引入顶部导航 -->
        <div class="right_col" supplier="main">
            <div class="">
                <div class="page-title">
                    <div class="title_left">
                        <h3>${storageRecord.id == null ? '新增' : '修改'}入库单信息</h3>
                    </div>
                </div>
                <div class="clearfix"></div>

                <div class="row">
                    <div class="col-md-12 col-sm-12 col-xs-12">
                        <div class="x_panel">
                            <div class="x_content">
                                <form action="${ctx}/main/storageRecord/save" enctype="multipart/form-data"
                                        class="form-horizontal form-label-left"  novalidate method="post">
                                    <%--   修改时隐藏域提交入库单id  --%>
                                    <input value="${storageRecord.id}" name="id"  type="hidden" />
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="srCode">
                                            入库编号 <span class="required">*</span>
                                        </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <c:if test="${empty storageRecord.id}">
                                                <input id="srCode" class="form-control col-md-7 col-xs-12"
                                                       value="${storageRecord.srCode}" name="srCode"
                                                       required="required" type="text">
                                            </c:if>
                                            <c:if test="${not empty storageRecord.id}">
                                                <input id="srCode" class="form-control col-md-7 col-xs-12"
                                                       value="${storageRecord.srCode}" name="srCode"
                                                       disabled="disabled" type="text">
                                            </c:if>
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="goodsName">
                                            商品名称 <span class="required">*</span>
                                        </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input id="goodsName" class="form-control col-md-7 col-xs-12"
                                                   value="${storageRecord.goodsName}" name="goodsName"
                                                   required="required" type="text">
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="goodsUnit">
                                            商品单位 <span class="required">*</span>
                                        </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input id="goodsUnit" class="form-control col-md-7 col-xs-12"
                                                   value="${storageRecord.goodsUnit}" name="goodsUnit"
                                                   required="required" type="text">
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="goodsCount">
                                            入库数量 <span class="required">*</span>
                                        </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input id="goodsCount" class="form-control col-md-7 col-xs-12"
                                                   value="${storageRecord.goodsCount}" name="goodsCount"
                                                   required="required" type="number">
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="totalAmount">
                                            总金额 <span class="required">*</span>
                                        </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input id="totalAmount" class="form-control col-md-7 col-xs-12"
                                                   value="${storageRecord.totalAmount}" name="totalAmount"
                                                   required="required" type="number">
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="supplierId">
                                            供应商
                                        </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <select id="supplierId" name="supplierId" class="form-control">
                                                <c:forEach items="${supplierList}" var="supplier">
                                                    <option value="${supplier.id}" ${supplier.id == storageRecord.supplierId ? "selected='selected'" : ""}>${supplier.supName}</option>
                                                </c:forEach>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12" >
                                            付款状态 <span class="required">*</span>
                                        </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input type="radio" class="flat" name="payStatus" id="payStatus1" value="1"
                                            ${storageRecord.payStatus == 1 ? "checked='checked'" : ""} required />
                                            未支付
                                            <input type="radio" class="flat" name="payStatus" id="payStatus2" value="2"
                                            ${storageRecord.payStatus == 2 ? "checked='checked'" : ""}/>
                                            已支付
                                        </div>
                                    </div>
                                    <div class="ln_solid"></div>
                                    <div class="form-group">
                                        <div class="col-md-6 col-md-offset-3">
                                            <button id="send" type="submit" class="btn btn-success">提交</button>
                                            <button type="button" onclick="history.back()" class="btn btn-primary">返回</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- 底部内容 -->
        <jsp:include page="/WEB-INF/layout/footer.jsp"></jsp:include>
        <!-- 底部内容 -->

        <script type="text/javascript" src="${ctx}/statics/js/common/save.js"></script>

        <script>
            $(function(){
                $("#srCode").on("input", function (){
                    // 输入过程中清除显示信息
                    clearInfo("#srCode");
                }).on("blur", function (){
                    // 失去焦点事件中，请求后端检查srCode是否存在
                    $.ajax({
                        type:"GET",//请求类型
                        url: ctx + "/main/storageRecord/srCodeExist",//请求的url
                        data:{ srCode: $(this).val() },//请求参数
                        dataType:"json",//ajax接口（请求url）返回的数据类型
                        success:function(data){//data：返回数据（json对象）
                            if(data.exist == 1){
                                //账号已存在，提示错误提示
                                showErrorInfoFor("#srCode", "该入库单编号已存在")
                            }else if(data.exist == 0){
                                //账号可用，提示正确提示
                                showSuccessInfoFor("#srCode", "该入库单编号可以使用")
                            }else if(data.error){
                                // 后台传了错误提示，显示
                                showErrorInfoFor("#srCode", data.error)
                            }
                        },
                        error:function(data){//当访问时候，404，500 等非200的错误状态码
                            showErrorInfoFor("#srCode", "请求异常，请联系管理员解决！")
                        }
                    });
                })
            })
        </script>

    </div>
</div>

</body>
</html>

